package indzcraft.ranking;

import indzcraft.loader.Enchant;
import indzcraft.loader.Gem;
import indzcraft.loader.ItemEquiped;
import indzcraft.loader.Reforge;
import indzcraft.ui.IndzCraftUI;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class ItemCompare<T> {
	
	IndzCraftUI icui;
	ItemEquiped item;
	ArrayList<T> items;
	ArrayList<EP<T>> comparedItems;
	
	public ItemCompare(IndzCraftUI iu,ItemEquiped i,ArrayList<T> items){
		this.icui = iu;
		this.item = i;
		this.items = items;
		comparedItems = new ArrayList<EP<T>>();
		
		Iterator<T> ie = items.iterator();
		while(ie.hasNext()){
			T item = ie.next();
			double ep = 0;
			if(item instanceof ItemEquiped){
				ep = icui.getCalc().calcItemEP((ItemEquiped) item);
				((ItemEquiped) item).setEP(ep);
			}
			else if(item instanceof Gem){
				ep = icui.getCalc().calcGemEP((Gem) item);
			}
			else if(item instanceof Enchant){
				ep = icui.getCalc().calcEnchantEP((Enchant) item);
			}
			else if(item instanceof Reforge){
				ep = icui.getCalc().calcReforgeEP(this.item,(Reforge) item);
			}
			comparedItems.add(new EP<T>(item, ep));
		}
		Collections.sort(comparedItems);
		
	}
	
	public ArrayList<EP<T>> getComperator(){		
		return comparedItems;
	}
}
